testgtk: Use pixbufs instead of pixmaps
authorBenjamin Otte <otte@redhat.com>
Fri, 6 Aug 2010 20:09:08 +0000 (22:09 +0200)
committerBenjamin Otte <otte@redhat.com>
Tue, 10 Aug 2010 19:02:31 +0000 (21:02 +0200)
This is for creating a GtkImage with an icon.

tests/testgtk.c

index 33c40c021de4f4a76400fcf642b524b3b81b5511..5ad59bfc40996d54e1937ac2f7052ecf6b04c9c8 100644 (file)
@@ -1252,29 +1252,26 @@ create_button_box (GtkWidget *widget)
  */
 
 static GtkWidget*
-new_pixmap (char      *filename,
+new_pixbuf (char      *filename,
            GdkWindow *window,
            GdkColor  *background)
 {
-  GtkWidget *wpixmap;
-  GdkPixmap *pixmap;
-  GdkBitmap *mask;
+  GtkWidget *widget;
+  GdkPixbuf *pixbuf;
 
-  if (strcmp (filename, "test.xpm") == 0 ||
-      !file_exists (filename))
-    {
-      pixmap = gdk_pixmap_create_from_xpm_d (window, &mask,
-                                            background,
-                                            openfile);
-    }
+  if (strcmp (filename, "test.xpm") == 0)
+    pixbuf = NULL;
   else
-    pixmap = gdk_pixmap_create_from_xpm (window, &mask,
-                                        background,
-                                        filename);
+    pixbuf = gdk_pixbuf_new_from_file (filename, NULL);
+
+  if (pixbuf == NULL)
+    pixbuf = gdk_pixbuf_new_from_xpm_data ((const char **) openfile);
   
-  wpixmap = gtk_image_new_from_pixmap (pixmap, mask);
+  widget = gtk_image_new_from_pixbuf (pixbuf);
+
+  g_object_unref (pixbuf);
 
-  return wpixmap;
+  return widget;
 }
 
 
@@ -1433,7 +1430,7 @@ create_toolbar (GtkWidget *widget)
             {
               GtkWidget *icon;
 
-              icon = new_pixmap ("test.xpm", window->window,
+              icon = new_pixbuf ("test.xpm", window->window,
                                  &window->style->bg[GTK_STATE_NORMAL]);
               toolitem = gtk_tool_button_new (icon, create_toolbar_items[i].label);
             }
@@ -1504,7 +1501,7 @@ make_toolbar (GtkWidget *window)
           toolitem = gtk_separator_tool_item_new ();
           continue;
         }
-      icon  = new_pixmap ("test.xpm", window->window,
+      icon  = new_pixbuf ("test.xpm", window->window,
                           &window->style->bg[GTK_STATE_NORMAL]);
       toolitem = gtk_tool_button_new (icon, make_toolbar_items[i].label);
       gtk_tool_item_set_tooltip_text (toolitem, make_toolbar_items[i].tooltip);
@@ -2920,7 +2917,7 @@ create_pixmap (GtkWidget *widget)
       button = gtk_button_new ();
       gtk_box_pack_start (GTK_BOX (box2), button, FALSE, FALSE, 0);
 
-      pixmapwid = new_pixmap ("test.xpm", window->window, NULL);
+      pixmapwid = new_pixbuf ("test.xpm", window->window, NULL);
 
       label = gtk_label_new ("Pixmap\ntest");
       box3 = gtk_hbox_new (FALSE, 0);
@@ -2932,7 +2929,7 @@ create_pixmap (GtkWidget *widget)
       button = gtk_button_new ();
       gtk_box_pack_start (GTK_BOX (box2), button, FALSE, FALSE, 0);
       
-      pixmapwid = new_pixmap ("test.xpm", window->window, NULL);
+      pixmapwid = new_pixbuf ("test.xpm", window->window, NULL);
 
       label = gtk_label_new ("Pixmap\ntest");
       box3 = gtk_hbox_new (FALSE, 0);